/***
 *
 * 一个事件绑定器的Event.js
 *
 * Daniel
 *
 * 2018.08.09
 *
 * **/

define(function () {
    var scope;
    var Event = function () {
        scope = this;
        this.world = {};
        this.flag = true;
    };
    
    //初始化事件
    Event.prototype.init = function(world){
        if(!(world instanceof Object))return this.flag = false;
        this.world = world;
        this.requestAnimationFrame = this.world.render;
    };
    
    //添加事件
    Event.prototype.addEvent = function (dom, type, listener, options) {
        if(dom==undefined || !scope.flag)return;
        var bool;
        options!==undefined ? bool=options : bool=false;
        dom.addEventListener(type,function(){
            listener();
        },bool);
        scope.requestAnimationFrame();
    };
    
    //移除事件
    Event.prototype.removeEvent = function (dom, type, listener, options) {
        if(dom==undefined || !scope.flag)return;
        var bool;
        options!==undefined ? bool=options : bool=false;
        dom.removeEventListener(type,function(){
            listener();
        },bool);
    };
    
    return Event;
});